package principle.open.close;

public class OpenClose {

    private Graphic graphic = new Graphic();


    // 客户端代码
    public static void main(String[] args) {
        OpenClose openClose = new OpenClose();
        openClose.start();
    }

    private void start() {
        graphic.draw(new Circle());
    }
}


// 使用方
class Graphic {
    public void draw(Shape shape) {
        shape.draw();
    }
}


// 以下为提供方
interface Shape {
    void draw();
}

class Rectangle implements Shape {

    @Override
    public void draw() {
        System.out.println("画方形");
    }
}

class Circle implements Shape {

    @Override
    public void draw() {
        System.out.println("画圆形");
    }
}
